package com.oa.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.oa.base.BaseDaoImpl;
import com.oa.dao.ReplyDao;
import com.oa.entity.Reply;
@SuppressWarnings("unchecked")
@Repository("replyDao")
public class ReplyDaoImpl extends BaseDaoImpl<Reply> implements ReplyDao {

	public List<Reply> queryDetailTopic(String topicId) {
		return getSession().createQuery("From Reply r where r.topic=:topicId")
				.setString("topicId", topicId).list();
	}

	public Reply queryLastReply(String postingId) {
		return (Reply) getSession().createQuery("from Reply r where r.postingTime=(select max(r2.postingTime) from Reply r2 where r2.topic=:postingId)")
				.setString("postingId", postingId).uniqueResult();
	}

	public boolean updateReply2(Object object) {
		try{
			getSession().update(object);
			return true;
		}catch(Exception e){
			return false;
		}
	}

}
